import { PROD_LIST, PROD_ITEM } from '../constants/product'

const INITIAL_STATE = {
    prodList: [],
    pages: 1,
    prodInfo: {}
}

export default function product(state = INITIAL_STATE, action) {
    switch (action.type) {
        case PROD_LIST: {
            return {
                ...state,
                pages: action.payload.pages,
                prodList: action.payload.current == 1 ? action.payload.records : state.prodList.concat(action.payload.records)
            }
        }
        case PROD_ITEM: {
            return {
                ...state,
                prodInfo: action.payload
            }
        }
        default: {
            return state
        }
    }
}